package de.tempel.fittslaw.objects;

import java.awt.Point;

import processing.core.PApplet;
import de.tempel.fittslaw.objects.interfaces.Drawable;

/**
 * 
 * Ziel auf das geklickt werden soll.
 * 
 * @author pfluegkuffer
 * 
 */
public class Target implements Drawable {

	private static final int DISTANCE_TO_WINDOW = 40;

	private int xPosition;
	private int windowHeight;
	private int width;

	boolean isClickable = true;
	int color = 255;

	public Target(int xPosition, int width, int windowHeight) {
		this.xPosition = xPosition;
		this.windowHeight = windowHeight;
		this.width = width;
	}

	public Target(Target otherTarget, int distance, int windowHeight) {
		this.width = otherTarget.getWidth();
		this.xPosition = otherTarget.getxPosition() + otherTarget.getWidth()
				+ distance;
		this.windowHeight = windowHeight;
	}

	public boolean touches(Point p) {
		if (p.getX() < xPosition) {
			return false;
		}
		if (p.getX() > xPosition + width) {
			return false;
		}
		if (p.getY() < DISTANCE_TO_WINDOW) {
			return false;
		}
		if (p.getY() > windowHeight - DISTANCE_TO_WINDOW * 2) {
			return false;
		}
		return true;
	}

	@Override
	public void draw(PApplet window) {
		window.fill(color);
		window.stroke(0);
		window.rect(this.getxPosition(), DISTANCE_TO_WINDOW, width,
				windowHeight - DISTANCE_TO_WINDOW * 2);
	}

	public boolean isClickable() {
		return isClickable;
	}

	public void setClickable(boolean isClickable) {
		this.isClickable = isClickable;
		if (isClickable) {
			color = 200;
		} else {
			color = 100;
		}
	}

	public int getColor() {
		return color;
	}

	public void setColor(int color) {
		this.color = color;
	}

	public int getxPosition() {
		return xPosition;
	}

	public void setxPosition(int xPosition) {
		this.xPosition = xPosition;
	}

	public int getWindowHeight() {
		return windowHeight;
	}

	public void setWindowHeight(int windowHeight) {
		this.windowHeight = windowHeight;
	}

	public int getWidth() {
		return width;
	}

	public void setWidth(int width) {
		this.width = width;
	}

	public void reset() {
		setClickable(true);
		color = 255;
	}

}
